﻿using HardToolApp.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HardToolApp.View
{
    /// <summary>
    /// APIHelper.xaml 的交互逻辑
    /// </summary>
    public partial class APIHelper : Window
    {
        static ObservableCollection<APIObject> APIs = new ObservableCollection<APIObject>();
        public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
        public static IEnumerable<IGrouping<string, APIObject>> groupedFunc;
        public static IEnumerable<IGrouping<string, APIObject>> GroupedFunc { get => groupedFunc; set { groupedFunc = value; StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(GroupedFunc))); } }
        public APIHelper()
        {
            InitializeComponent();

            APIGrid.ItemsSource = GroupedFunc;
        }

        public static void Add(string typeName, string funcName,string param,string res,string note)
        {
            APIs.Add(new APIObject(typeName,funcName,param,res,note));
            APIHelper.GroupedFunc = APIs.GroupBy(x => x.typeName);
        }

        public class APIObject
        {
            public string typeName { get; set; }
            public string funcName { get; set; }
            public string param { get; set; }
            public string res { get; set; }
            public string note { get; set; }
            public APIObject(string typeName, string funcName, string param, string res, string note)
            {
                this.typeName = typeName;
                this.funcName = funcName;
                this.param = param;
                this.res = res;
                this.note = note;
            }
        }

    }
}
